const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';
const jsonflatten = require('pt-core-common').util.jsonflatten;

const putTransportContent = {};
putTransportContent.generateOption = function(seller_id, mws_auth_token, shipmentId, shipmentType, isPartnered, transportDetails=null){
  let baseOption = {
    'Version': '2010-10-01',
    'Action': 'PutTransportContent',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'ShipmentId': shipmentId,
    'ShipmentType': shipmentType,
    'IsPartnered': isPartnered,
  };

  const option = Object.assign(baseOption,
    jsonflatten.flatten(transportDetails, null, baseIndex=1));
  return option;
};

putTransportContent._ = function(options) {
  if (!isProduction) {
    return amazonMws.fulfillmentInboundShipment.search(options);
  } else {
    console.error("bot not implemented!")
  }
};

putTransportContent.putTransportContent = function(seller_id, mws_auth_token, shipmentId, shipmentType, isPartnered, transportDetails=null) {
  return this._(this.generateOption(seller_id, mws_auth_token, shipmentId, shipmentType, isPartnered, transportDetails));
};

module.exports = putTransportContent;